// virtual ~function.

#include <iostream>
#include <fcntl.h>
#include <unistd.h>
using namespace std;

class A {
	public:
		A( ) : m_a(open("./file", O_CREAT|O_RDWR, 0644)) {
			cout << "A( ) is invoked" << endl;
		}
		virtual ~A( ){
			close( m_a );
			cout << "~A( ) is invoked" << endl;
		}
	private:
		int m_a;
};

class B : public A {
	public:
		B( ) : m_b(open("./cfg", O_CREAT|O_RDWR, 0644)) {
			cout << "B( ) is invoked" << endl;
		}
		~B( ) {
			close( m_b );
			cout << "~B is invoked" << endl;
		}
	private:
		int m_b;
};

// designer
// ------------------------------------------------------------------
// user

int main( void ) {
	A* p = new B;	// define b class

	delete p;

	return 0;
}

